package com.ll.bignumber;

import java.math.BigDecimal;

/**
 * @author 刘龙
 * @version 1.0
 */
public class BigDecimalDemo {
    public static void main(String[] args) {
        BigDecimal bigDecimal = new BigDecimal("1999.99999999999999999999999999999");
        BigDecimal bigDecimal1 = new BigDecimal("0.7");

        // 1999.99999999999999999999999999999
        System.out.println(bigDecimal);

        // 加 2000.19999999999999999999999999999
        System.out.println(bigDecimal.add(bigDecimal1));

        // 减 1999.79999999999999999999999999999
        System.out.println(bigDecimal.subtract(bigDecimal1));

        //乘 399.999999999999999999999999999998
        System.out.println(bigDecimal.multiply(bigDecimal1));

        //  方法过时
        // 如果除的时候是除不尽的会抛出
        // Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        // 可以指定精度解决
        //除 9999.99999999999999999999999999995
        System.out.println(bigDecimal.divide(bigDecimal1, 2));
    }
}
